package com.bitongchong.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class SortByKeyExample {

	public static class User {
		private String userId;
		private Integer logTime;
		public String getUserId() {
			return userId;
		}
		public void setUserId(String userId) {
			this.userId = userId;
		}
		public Integer getLogTime() {
			return logTime;
		}
		public void setLogTime(Integer logTime) {
			this.logTime = logTime;
		}
		public User(String userId, Integer logTime) {
			super();
			this.userId = userId;
			this.logTime = logTime;
		}
	}
	
	public static class testCompar implements Comparator<User>{
		@Override
		public int compare(User o1, User o2) {

			if (o1.getUserId().equals(o2.getUserId())) {
				return o1.getLogTime().compareTo(o2.getLogTime());
			} else {
				return o1.getUserId().compareTo(o2.getUserId());
			}
		}
	}
	
	public static void printWrongCount(List<User> list) {
		int userId = 0;
		int logCount = 0;
		List<String> list2 = new ArrayList<>();
		while (logCount < list.size()) {
			if (list.get(userId).getUserId().equals(list.get(logCount).getUserId())){
				if (list.get(logCount).getLogTime() - list.get(userId).getLogTime() <= 3600 && (logCount - userId) == 5) {
					list2.add(list.get(userId).getUserId());
				} else if(list.get(logCount).getLogTime() - list.get(userId).getLogTime() > 3600) {
					userId++;
				}
			} else {
				userId = logCount;
			}
			logCount++;
		}
		for (int i = 0; i < list2.size(); i++) {
			System.out.println(list2.get(i));
		}
	}
	
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		List<User> list = new ArrayList<>();
		String lineCount = sc.nextLine();
		int count = Integer.parseInt(lineCount);
		for (int i = 0; i < count; i++) {
			String str = sc.nextLine();
			String[] splitArr = str.split(" ");
			if (splitArr[0].charAt(0) == 's') {
				String[] split2 = splitArr[1].split(":");
				int sum = 0;
				for (int j = 0; j < split2.length; j++) {
					sum += Integer.parseInt(split2[j]) * Math.pow(60, split2.length - j - 1);
				}
				list.add(new User(splitArr[0], sum));
			}
		}
		Collections.sort(list, new testCompar());
		printWrongCount(list);
	}
}
